

VER_H=../../include/bearssl/bearssl_git.h

all T0 clean: bearssl/README.txt
	PATH="$(PWD)/../../system/arm-none-eabi/bin/:$(PATH)" && arm-none-eabi-gcc --version && cd bearssl && $(MAKE) CONF=pico $@

install: all version-header
	cp bearssl/pico/libbearssl.a ../../lib/rp2040/.
	ar d ../../lib/rp2040/libbearssl.a `ar t ../../lib/rp2040/libbearssl.a | egrep 'x86|sse|pwr8|i62|m32|m62|m64|ct64|ctmul64'` # Remove unneeded objects
	cp bearssl/inc/bearssl*.h ../../include/bearssl/.

all2: bearssl/README.txt
	PATH="$(PWD)/../../system/arm-none-eabi/bin/:$(PATH)" && arm-none-eabi-gcc --version && cd bearssl && $(MAKE) CONF=pico2 clean all

install2: all2 version-header
	cp bearssl/pico2/libbearssl.a ../../lib/rp2350/.
	ar d ../../lib/rp2350/libbearssl.a `ar t ../../lib/rp2350/libbearssl.a | egrep 'x86|sse|pwr8|i62|m32|m62|m64|ct64|ctmul64'` # Remove unneeded objects
	cp bearssl/inc/bearssl*.h ../../include/bearssl/.

all2rv: bearssl/README.txt
	PATH="$(PWD)/../../system/riscv32-unknown-elf/bin/:$(PATH)" && riscv32-unknown-elf-gcc --version && cd bearssl && $(MAKE) CONF=pico2rv clean all

install2rv: all2rv version-header
	cp bearssl/pico2rv/libbearssl.a ../../lib/rp2350-riscv/.
	ar d ../../lib/rp2350-riscv/libbearssl.a `ar t ../../lib/rp2350-riscv/libbearssl.a | egrep 'x86|sse|pwr8|i62|m32|m62|m64|ct64|ctmul64'` # Remove unneeded objects
	cp bearssl/inc/bearssl*.h ../../include/bearssl/.

bearssl/README.txt:
	git submodule update --init --recursive bearssl
	cd bearssl && (git remote add bearssl https://www.bearssl.org/git/BearSSL || true)

merge-upstream:
	cd bearssl && git pull bearssl master

version-header:
	echo "// Do not edit -- Automatically generated by tools/sdk/ssl/bearssl/Makefile" > $(VER_H)
	echo -n "#define BEARSSL_GIT " >> $(VER_H)
	cd bearssl && git rev-parse --short HEAD >> ../$(VER_H)

native: bearssl/README.txt
	cd bearssl && make

native32: bearssl/README.txt
	cd bearssl && make CONF=Unix32
